﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace D2E.Shared.Common.Settings
{
    public class XMLSettings
    {
        public string Path { get; set; }

        private XmlDocument _document { get; set; }

        public XMLSettings(string path)
        {
            this.Path = path;
            this.load();
        }

        private void load()
        {
            var doc = new XmlDocument();
            doc.Load(this.Path);
            this._document = doc;
        }

        public XmlNode GetXmlNode(string access)
        {
            XmlNode currentNode = this._document["Settings"];
            foreach (var a in access.Split('.'))
            {
                if (a != "")
                {
                    currentNode = currentNode[a];
                }
            }
            return currentNode;
        }

        public string GetValue(string access)
        {
            return this.GetXmlNode(access).InnerText;
        }

        public int GetIntValue(string access)
        {
            return int.Parse(this.GetValue(access));
        }

        public bool GetBoolValue(string access)
        {
            return bool.Parse(this.GetValue(access));
        }
    }
}
